data=[
    [0,0,0,0,0,0],
    [0,13,11,10,4,7],
    [0,13,10,10,8,5],
    [0,5,9,7,7,4],
    [0,15,12,10,11,5],
    [0,10,11,8,8,4]
]

maxValue = 0
bestPlan = [0] * 6
curPlan = [0] * 6
slots = [0] * 6

def go(step, t):
    global bestPlan, curPlan, slots, maxValue
    for i in range(1, 6):
        if slots[i] == 0:
            curPlan[step] = i
            slots[i] = 1
            t += data[step][i]
            if step < 5:
                go(step + 1, t)
            elif t > maxValue:
                maxValue = t
                bestPlan = curPlan[:]
            t -= data[step][i]
            slots[i] = 0

go(1, 0)

print(bestPlan[1:])
print("max:", maxValue)